<?php
 
/* data actually came from POST
$_POST = array(
    'product_id' => 'libgd<script>',
    'component'  => array('10'),
    'version'    => '2.0.33',
    'testarray'  => array('2', '23', '10', '12'),
    'testscalar' => '2',
);
*/



$args = array(
    'product_id'   => FILTER_SANITIZE_ENCODED,
    'component'    => array('filter'    => FILTER_VALIDATE_INT,
                            'flags'     => FILTER_REQUIRE_ARRAY, 
                            'options'   => array('min_range' => 1, 'max_range' => 10)
                           ),
    'version'      => FILTER_SANITIZE_ENCODED,
    'doesnotexist' => FILTER_VALIDATE_INT,
    'testscalar'   => array(
                            'filter' => FILTER_VALIDATE_INT,
                            'flags'  => FILTER_REQUIRE_SCALAR,
                           ),
    'testarray'    => array(
                            'filter' => FILTER_VALIDATE_INT,
                            'flags'  => FILTER_REQUIRE_ARRAY,
                           )

);

$myinputs = filter_input_array(INPUT_POST, $args);

echo "\n<pre>";
var_dump($myinputs);
echo "</pre>\n";
 
?>

<form method="post" >
<input type="text" value="libgd<script>" name="product_id"/>
    <label><input type="checkbox" name="component" value="10" checked>> 选项 1</label>
<input type="text" value="2.0.33" name="version"/>
<input type="text" value="2" name="testscalar"/>
 
 


<label><input type="checkbox" name="testarray" value="2" checked> 选项 1</label>
<label><input type="checkbox" name="testarray" value="23" checked> 选项 1</label>
<label><input type="checkbox" name="testarray" value="10" checked> 选项 1</label>
<label><input type="checkbox" name="testarray" value="12" checked> 选项 1</label>
 
 



<button>提交</button>
</form>
 





